package race

import "math/bits"

/**
 * @Description: 6124. 第一个出现两次的字母 简单
 * @Keyword:
 * @Author: kami
 * @Date: 2022/7/24 11:50
 **/
func repeatedCharacter(s string) byte {
	var dp = [26]byte{}

	for i := 0; i < len(s); i++ {
		if dp[s[i]-'a'] == '1' {
			return s[i]
		}
		dp[s[i]-'a'] = '1'
	}
	return ' '
}

/**
 * @Description: 6125. 相等行列对
 * @Keyword:
 * @Author: kami
 * @Date: 2022/7/24 11:55
 **/
func equalPairs(grid [][]int) int {
	var row = len(grid) - 1
	var col = len(grid[0]) - 1
	var cnt int
	for i := 0; i <= row; i++ {
		for j := 0; j <= col; j++ {
			cnt++
			for k := 0; k <= row; k++ {
				if grid[i][k] != grid[k][j] {
					cnt--
					break
				}
			}
		}
	}
	return cnt
}

/**
 * @Description: 6127. 优质数对的数目  困难
 * @Keyword:
 * @Author: kami
 * @Date: 2022/7/24 12:56
 **/
func countExcellentPairs(nums []int, k int) int64 {
	vis := map[int]bool{}
	cnt := map[int]int{}
	for _, x := range nums {
		if !vis[x] {
			vis[x] = true
			cnt[bits.OnesCount(uint(x))]++
		}
	}
	var ans int64
	for cx, ccx := range cnt {
		for cy, ccy := range cnt {
			if cx+cy >= k { // (x,y) 是优质数对
				ans += int64(ccx) * int64(ccy)
			}
		}
	}
	return ans

}
